package com.qianfeng.bob.xiexiaobo.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.qianfeng.bob.xiexiaobo.R;
import com.qianfeng.bob.xiexiaobo.application.MyApplication;
import com.qianfeng.bob.xiexiaobo.cache.MyCache;

import java.util.List;

/**
 * Created by Bob on 2015/12/17.
 */
public abstract class MyBaseAdapter<T> extends android.widget.BaseAdapter {
    private List<T> mDatas;
    private LayoutInflater mInflater;
    private RequestQueue mRequest  ;
    private MyCache mCache ;
    public MyBaseAdapter(Context context,List<T> datas){
        mInflater = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE));
        mDatas = datas;
        mRequest =((MyApplication) ((Activity)context).getApplication()).getRequestQueue();
        mCache = ((MyApplication) ((Activity)context).getApplication()).getMyCache();
    }
    @Override
    public int getCount() {
        return mDatas==null?0:mDatas.size();
    }

    @Override
    public T getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        return getView(position,convertView,parent,mInflater,mDatas);
    }
    public abstract  View getView(int position, View convertView, ViewGroup parent, LayoutInflater inflater,List<T> datas);

    public   void loadImage(ImageView imageView){
        String url = ((String) imageView.getTag());
        ImageLoader.ImageListener listener = ImageLoader.getImageListener(imageView, R.mipmap.bottom_comment_input,R.mipmap.bottom_comment_input);
        ImageLoader loader = new ImageLoader(mRequest,mCache);
        loader.get(url,listener);
    }
}
